using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.CRMDomain;
using ShivamEMR.Model.DataInterfaces.CRMDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.CRM.Controllers
{   
    public class AppointmentGroupController : Controller
    {
		private readonly IAppointmentGroupRepository appointmentgroupRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public AppointmentGroupController()// : this(new AppointmentGroupRepository())
        {
            this.appointmentgroupRepository = Registry.RepositoryFactory.GetAppointmentGroupRepository();
        }

        public AppointmentGroupController(IAppointmentGroupRepository appointmentgroupRepository)
        {
			this.appointmentgroupRepository = appointmentgroupRepository;
        }

        //
        // GET: /AppointmentGroup/

        public ViewResult Index()
        {
            return View(appointmentgroupRepository.All);//Including(appointmentgroup => appointmentgroup.Parent, appointmentgroup => appointmentgroup.Children, appointmentgroup => appointmentgroup.Appointments));
        }

        //
        // GET: /AppointmentGroup/Details/5

        public ViewResult Details(int id)
        {
            return View(appointmentgroupRepository.Find(id));
        }

        //
        // GET: /AppointmentGroup/Create

        public ActionResult Create()
        {
			ViewBag.PossibleParents = appointmentgroupRepository.All;
            return View();
        } 

        //
        // POST: /AppointmentGroup/Create

        [HttpPost]
        public ActionResult Create(AppointmentGroup appointmentgroup)
        {
            if (ModelState.IsValid) {
                appointmentgroupRepository.InsertOrUpdate(appointmentgroup);
                appointmentgroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleParents = appointmentgroupRepository.All;
				return View();
			}
        }
        
        //
        // GET: /AppointmentGroup/Edit/5
 
        public ActionResult Edit(int id)
        {
			ViewBag.PossibleParents = appointmentgroupRepository.All;
             return View(appointmentgroupRepository.Find(id));
        }

        //
        // POST: /AppointmentGroup/Edit/5

        [HttpPost]
        public ActionResult Edit(AppointmentGroup appointmentgroup)
        {
            if (ModelState.IsValid) {
                appointmentgroupRepository.InsertOrUpdate(appointmentgroup);
                appointmentgroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleParents = appointmentgroupRepository.All;
				return View();
			}
        }

        //
        // GET: /AppointmentGroup/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(appointmentgroupRepository.Find(id));
        }

        //
        // POST: /AppointmentGroup/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            var a = appointmentgroupRepository.Find(id);
            appointmentgroupRepository.Delete(a);
            appointmentgroupRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

